package itheima.com.SocketApi;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
//服务器
public class SocketServer {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("服务器serverSocket ...........");

        Socket accept = serverSocket.accept();
        System.out.println("服务器accept ...........");


        byte[] buf = new byte[1024];
        int len = 0;
        InputStream inputStream = accept.getInputStream();
        while ((len = inputStream.read(buf)) != -1) {
            System.out.println("读取客户端数据事："+new String(buf, 0, len));
        }

        OutputStream outputStream = accept.getOutputStream();
        outputStream.write("那肯定那会加快速度换个卡垃圾".getBytes());
        accept.shutdownOutput();


        serverSocket.close();
        accept.close();
        inputStream.close();
        System.out.println("服务器退出...........");
    }

}
